//--------第一题--------------
//判断是否闰年
function isRunYear(year) {
    if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
        return true
    } else {
        return false
    }
}

function days(year, month, day) {
    var runYear = isRunYear(year);
    //大月的数组
    var bigMonth = [1, 3, 5, 7, 8, 10, 12];
    //小月的数组
    var samllMonth = [4, 6, 9, 11];
    //通过三元运算计算2月的天数，如果是闰年则29天，否则28天。
    var erYue = runYear ? 29 : 28;
    //结果天数
    var daySum = 0
        //计算本月之前所有月份的天数总合
    for (var m = 1; m < month; m++) {
        if (bigMonth.includes(m)) {
            daySum += 31;
        } else if (samllMonth.includes(m)) {
            daySum += 30;
        } else {
            daySum += erYue
        }
    };
    //循环结束之后再加的天数
    daySum += day;
    return daySum
}

var totalDays = days(2012, 12, 31)
console.log(totalDays)

//-----------第二题----------
var max = function(x, y) {
    if (x - y >= 0) {
        return x
    } else {
        return y
    }
}

//--------第三题------------
function lower(str) {
    return str.toLowerCase()
}

//----------第四题----------

function randomBetween(min, max) {
    var x = Math.random();
    var m = max - min
    return Math.round(m * x + min);
}

function randomArray() {
    var max, min, len;
    var res = [];
    if (arguments.length == 0) {
        len = 5;
        for (var i = 1; i <= len; i++) {
            res.push(randomBetween(0, 100))
        }
    } else if (arguments.length == 1) {
        len = arguments[0];
        for (var i = 1; i <= len; i++) {
            res.push(randomBetween(0, 100))
        }
    } else if (arguments.length == 2) {
        len = arguments[0];
        for (var i = 1; i <= len; i++) {
            res.push(randomBetween(arguments[1], 100))
        }
    } else {
        len = arguments[0];
        for (var i = 1; i <= len; i++) {
            res.push(randomBetween(arguments[1], arguments[2]))
        }
    };
    return res
}

function squreArray(array) {
    var res = [];
    res = array.map(function(item) {
        return item ** 2
    });
    res.sort(function(a, b) { return a - b });
    return res
}